{extend name="layouts/app"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">编辑角色</div>
    <div class="layui-card-body">
        <form class="layui-form" action="{:url('update')}">
            <div class="layui-form-item">
                <label class="layui-form-label">角色名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" value="{$authGroup->title}" lay-verify="required" autocomplete="off" placeholder="角色名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">角色描述</label>
                <div class="layui-input-inline">
                    <textarea name="description" placeholder="角色的相关描述" class="layui-textarea">{$authGroup->description}</textarea>
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" title="开启" {eq name="$authGroup->status" value="1"}checked{/eq} >
                    <input type="radio" name="status" value="0" title="关闭" {eq name="$authGroup->status" value="0"}checked{/eq} >
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选择权限</label>
                <div class="layui-input-inline">
                    <div id="LAY-auth-tree-index"></div>
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" name="id" value="{$authGroup->id}">
                    <button class="layui-btn" lay-submit="" lay-filter="formSubmit">立即提交</button>
                    <button class="layui-btn layui-btn-normal" type="button" onclick="javascript:history.back(-1);">返回</button>
                </div>
            </div>
        </form>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    layui.extend({
        authtree: 'authtree/authtree',
    }).use(['jquery', 'form', 'layer','authtree'], function () {
        var $=layui.jquery,
            form=layui.form,
            authtree=layui.authtree;
        var auth_group_id = "{$authGroup->id}"
        $.ajax({
            url: "{:url('apiGetMenus')}",
            dataType: 'json',
            data:{auth_group_id:auth_group_id},
            success: function(data){
                var trees = authtree.listConvert(data.data.list,{
                    primaryKey: 'id'
                    ,startPid: 0
                    ,parentKey: 'parent_id'
                    ,nameKey: 'title'
                    ,valueKey: 'id'
                    ,checkedKey: data.data.checkedId
                });
                authtree.render('#LAY-auth-tree-index', trees, {
                    inputname: 'rules[]',
                    layfilter: 'lay-check-auth',
                    autowidth: true,
                    openall:true
                });
            }
        });
    });
</script>
{/block}